class Logger {
    constructor() {
        if (!Logger.instance) {
            this.logs = []
            Logger.instance = this
        }
        return Logger.instance
    }

    log (message) {
        this.logs.push(message)
        console.log(`Logger: ${message}`)
    }

    printLogCount () {
        console.log(this.logs.length)
    }
}

// 可以使用全局变量类访问实例
const logger = new Logger()
Object.freeze(logger)

// 对于每个实例，输出应该是相同的
logger.log('First message')
logger.printLogCount()

const anotherLogger = new Logger()
anotherLogger.log('Second message')
anotherLogger.printLogCount()